package pay.mapper;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.taxation.web.project.pay.module.channel.PayChannelDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

@Mapper
public interface PayChannelMapper extends BaseMapperX<PayChannelDO> {

    default PayChannelDO selectByAppIdAndCode(String appId, String code) {
        return selectOne(PayChannelDO::getAppId, appId, PayChannelDO::getCode, code);
    }

//    default PageResult<PayChannelDO> selectPage(PayChannelPageReqVO reqVO) {
//        return selectPage(reqVO, new QueryWrapperX<PayChannelDO>()
//                .eqIfPresent("code", reqVO.getCode())
//                .eqIfPresent("status", reqVO.getStatus())
//                .eqIfPresent("remark", reqVO.getRemark())
//                .eqIfPresent("fee_rate", reqVO.getFeeRate())
//                .eqIfPresent("merchant_id", reqVO.getMerchantId())
//                .eqIfPresent("app_id", reqVO.getAppId())
//                .betweenIfPresent("create_time", reqVO.getCreateTime())
//                .orderByDesc("id"));
//    }

//    default List<PayChannelDO> selectList(PayChannelExportReqVO reqVO) {
//        return selectList(new QueryWrapperX<PayChannelDO>()
//                .eqIfPresent("code", reqVO.getCode())
//                .eqIfPresent("status", reqVO.getStatus())
//                .eqIfPresent("remark", reqVO.getRemark())
//                .eqIfPresent("fee_rate", reqVO.getFeeRate())
//                .eqIfPresent("merchant_id", reqVO.getMerchantId())
//                .eqIfPresent("app_id", reqVO.getAppId())
//                .betweenIfPresent("create_time", reqVO.getCreateTime())
//                .orderByDesc("id"));
//    }

    /**
     * 根据条件获取渠道数量
     *
     * @param merchantId 商户编号
     * @param appid      应用编号
     * @param code       渠道编码
     * @return 数量
     */
    default Integer selectCount(String merchantId, String appid, String code) {
        return this.selectCount(new QueryWrapper<PayChannelDO>().lambda()
                .eq(PayChannelDO::getMerchantId, merchantId)
                .eq(PayChannelDO::getAppId, appid)
                .eq(PayChannelDO::getCode, code)).intValue();
    }

    /**
     * 根据条件获取渠道
     *
     * @param merchantId 商户编号
     * @param appI      应用编号
     * @param code       渠道编码
     * @return 数量
     */
    default PayChannelDO selectOne(String merchantId, String appI, String code) {
        return this.selectOne((new QueryWrapper<PayChannelDO>().lambda()
                .eq(PayChannelDO::getMerchantId, merchantId)
                .eq(PayChannelDO::getAppId, appI)
                .eq(PayChannelDO::getCode, code)
        ));
    }

    /**
     * 根据支付应用ID集合获得支付渠道列表
     *
     * @param appIds 应用编号集合
     * @return 支付渠道列表
     */
    default List<PayChannelDO> getChannelListByAppIds(Collection<String> appIds){
        return this.selectList(new QueryWrapper<PayChannelDO>().lambda()
                .in(PayChannelDO::getAppId, appIds));
    }

}
